<?php
/**
 * Created by PhpStorm.
 * User: 宇
 * Date: 2016/9/26
 * Time: 9:06
 */
namespace app\index\controller;

use think\Controller;
use think\Request;
use app\index\model\Content;
use app\common\controller\Index;

class Search extends Controller
{
    /*
     * 搜索展示
     */
    public function index()
    {

    }

    /*
     * 搜索
     */

    public function search(Request $request)
    {
        $_dosubmit = $request -> get('dosubmit');
        if ('' == $_dosubmit) {
            //过滤
            $title_input = $request -> get('title');
            $input_vali = new Index();
            $title = $input_vali ->validateInput($title_input);
            //模糊搜索获取商品数据
            $goods_list  = model('Content') -> where('title','like',"%$title%") -> paginate(5, false, [
                'query' => array(
                    'dosubmit' => '',
                    'title' => $title,
                )
            ]);
            $this->assign('list',$goods_list);

            $this->view->replace([
                '__PUBLIC__'    =>  'static/',
                '__ROOT__'      =>  '/daogou/public/'
            ]);
            return $this->fetch();
        }
        return $this->fetch();
    }
}